﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace Xinnos.Lca.Yacht.Analyzer.View
{
    /// <summary>
    /// Interaction logic for ObjectRatioPanel.xaml
    /// </summary>
    public partial class ObjectRatioPanel : UserControl
    {
        public ObjectRatioPanel()
        {
            InitializeComponent();
            componentsColumn.ItemsSource = ComponentsViewModel.GetInstance().Components;
        }

        private void OnCanExecuteNewCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = null == this.DataContext ? false : null != this.DataContext as ObjectViewModel;
        }
        private void OnExecuteNewCommand(object sender, ExecutedRoutedEventArgs e)
        {
            ComponentRatioViewModel _ratio = new ComponentRatioViewModel();
            ObjectViewModel _context = this.DataContext as ObjectViewModel;
            _context.Ratios.Add(_ratio);
            _context.Ratio = _ratio;
        }

        private void OnCanExecuteRemoveCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            bool _enabled = false;
            if (null != this.DataContext)
            {
                ObjectViewModel _object = this.DataContext as ObjectViewModel;
                if (null != _object) _enabled = (null != _object.Ratio);
            }
            e.CanExecute = _enabled;
        }
        private void OnExecuteRemoveCommand(object sender, ExecutedRoutedEventArgs e)
        {
            ObjectViewModel _context = this.DataContext as ObjectViewModel;
            _context.Ratios.Remove(_context.Ratio);
            _context.Ratio = null;
        }
    }
}